package org.alwayssuper.protocol.commons.transform.realtimev2016.enums;

/**
 * 定位状态枚举 (车辆位置数据 0x05)
 * 基于 GB/T 32960.3-2016 标准
 * 定位状态位定义
 * @author alwaysSuper
 */
public class LocationStatus {
    
    /**
     * 定位有效性
     */
    public enum LocationValidity {
        VALID(0, "有效定位"),
        INVALID(1, "无效定位");
        
        private final int bit;
        private final String description;
        
        LocationValidity(int bit, String description) {
            this.bit = bit;
            this.description = description;
        }
        
        public int getBit() { return bit; }
        public String getDescription() { return description; }
    }
    
    /**
     * 纬度方向
     */
    public enum LatitudeDirection {
        NORTH(0, "北纬"),
        SOUTH(1, "南纬");
        
        private final int bit;
        private final String description;
        
        LatitudeDirection(int bit, String description) {
            this.bit = bit;
            this.description = description;
        }
        
        public int getBit() { return bit; }
        public String getDescription() { return description; }
    }
    
    /**
     * 经度方向
     */
    public enum LongitudeDirection {
        EAST(0, "东经"),
        WEST(1, "西经");
        
        private final int bit;
        private final String description;
        
        LongitudeDirection(int bit, String description) {
            this.bit = bit;
            this.description = description;
        }
        
        public int getBit() { return bit; }
        public String getDescription() { return description; }
    }
    
    /**
     * 解析定位状态字节
     * @param statusByte 定位状态字节
     * @return 解析结果数组 [有效性, 纬度方向, 经度方向]
     */
    public static String[] parseLocationStatus(int statusByte) {
        LocationValidity validity = (statusByte & 0x01) == 0 ? 
            LocationValidity.VALID : LocationValidity.INVALID;
        LatitudeDirection latitude = (statusByte & 0x02) == 0 ? 
            LatitudeDirection.NORTH : LatitudeDirection.SOUTH;
        LongitudeDirection longitude = (statusByte & 0x04) == 0 ? 
            LongitudeDirection.EAST : LongitudeDirection.WEST;
            
        return new String[]{validity.getDescription(), 
                          latitude.getDescription(), 
                          longitude.getDescription()};
    }
    
    /**
     * 检查定位是否有效
     * @param statusByte 定位状态字节
     * @return true=有效定位
     */
    public static boolean isValidLocation(int statusByte) {
        return (statusByte & 0x01) == 0;
    }
    
    /**
     * 检查是否为北纬
     * @param statusByte 定位状态字节
     * @return true=北纬
     */
    public static boolean isNorthLatitude(int statusByte) {
        return (statusByte & 0x02) == 0;
    }
    
    /**
     * 检查是否为东经
     * @param statusByte 定位状态字节
     * @return true=东经
     */
    public static boolean isEastLongitude(int statusByte) {
        return (statusByte & 0x04) == 0;
    }
}